<template>
  <div>
    <div v-show='isShow && !isHour'>
    <span class="countdown-num">{{minute}}</span>
    <span class="countdown-text">分</span>
    <span class="countdown-num">{{second}}</span>
    <span class="countdown-text">秒</span>
    </div>
    <div v-show='isShow && isHour'>
    <span class="countdown-num">{{hour}}</span>
    <span class="countdown-text">时</span>
    <span class="countdown-num">{{minute}}</span>
    <span class="countdown-text">分</span>
    <span class="countdown-num">{{second}}</span>
    <span class="countdown-text">秒</span>
    </div>
    <span class="countdown-text" v-show='!isShow'>等待开奖...</span>
  </div>
</template>
<script>
export default {
  data() {
    return {
      minute: "00",
      second: "00",
      hour: "00",
      endTime: null,
      nowTime: null,
      isShow: true,
      isHour: false,
      timer: null
    };
  },
  props: {
    TypeMessage: Object
  },
  watch: {
    getStore: function(data) {
      this.isShow = true;
      this.isHour = false;
      this.smallCountDown = data;
      this.endTime = this.smallCountDown.next_open_time;
      this.nowTime = this.smallCountDown.time;
      clearInterval(this.timer);
      // this.log('this.nowTime>>>',this.nowTime);
      // this.log('this.endTime>>>',this.endTime)
      this.countdowm();
    }
  },
  mounted() {},
  methods: {
    countdowm() {
      let self = this;
      let nowTime = self.nowTime;
      let endTime = self.endTime;
      let t = endTime - nowTime;
      // this.log('t>>>',t);
      this.timer = setInterval(function() {
        if (t > 0) {
          self.isShow = true;
          let hour = Math.floor((t / 3600000) % 60);
          let min = Math.floor((t / 60000) % 60);
          let sec = Math.floor((t / 1000) % 60);
          if (hour > 0) {
            self.isHour = true;
          } else {
            self.isHour = false;
          }
          hour = hour < 10 ? "0" + hour : hour;
          min = min < 10 ? "0" + min : min;
          sec = sec < 10 ? "0" + sec : sec;
          self.minute = min;
          self.second = sec;
          self.hour = hour;
          t = t - 1000;
        } else {
          clearInterval(this.timer);
          self.isShow = false;
        }
      }, 1000);
    }
  },
  computed: {
    getStore() {
      return this.TypeMessage;
    }
  }
};
</script>

<style lang="less" scoped>
@import url(../../../assets/css/countdown.less);
</style>


